<div id ="list_tally_number">
<div class="form-row">
    <label for="tally_in_bom" >BOM Number:</label>
  <div class="content">
  <? 
        $c = new Criteria();
        $c->add(BOMPeer::PROJECT_ID, $projectId);
        $c->addDescendingOrderByColumn(BOMPeer::WONO);
        $bomList = BOMPeer::doSelect($c);

    ?>
      <? if ($tally_in->getReviseId()) {?>
            <input type = "hidden" name="tally_in[tallyno]" id="tally_in_tallyno" value="<?echo $tally_in->getTallyno()?>"/>
            <select name="tally_in1[tallyno1]" id ="tally_in_tallyno1" class="TALLYOUT1"  onchange="BuildBomList()" disabled>
        <?}
        else {?>
            <select name="tally_in[tallyno]" id ="tally_in_tallyno" class="TALLYOUT"  onchange="BuildBomList()">
        <?}?>
        <option></option>
        <?
        foreach ($bomList as $bom)
        {
        ?>
        <option value="<? echo $bom->getId(); if ($tally_in->getTallyno() && $tally_in->getTallyno()==$bom->getId()) echo '" selected=1'?>"><? echo $bom->__toString() ?></option>
        <?
        }
        ?>
        </select>
    
</div>
</div>
</div>

<div id ="BOMcomplist">
<table id ='added_components' "cellspacing="0" class="sf_admin_list">
<thead>
<tr>
      <th id="sf_admin_list_th_productcode" width="25%">Product Code
              </th>
      <th id="sf_admin_list_th_description" width="35%">Description
              </th>
      <th id="sf_admin_list_th_description" width="10%">Brand
              </th>
      <th id="sf_admin_list_th_description" width="10%">Unit
              </th>
      <th id="sf_admin_list_th_description">Qty</th>
      <th id="sf_admin_list_th_description">Return Unused Qty</th>
</tr>
</thead>

<?php   

    $BOM = BOMPeer::retrieveByPK($tally_in->getTallyno());
    if ($BOM){
        $c = new Criteria();
        $c->add(ComponentsPeer::COMPONENTGROUP_ID, $BOM->getComponentgroupId());
        $compsList = ComponentsPeer::doSelect($c);
    }
?>
<?php if (isset($tally_in->rowIds) && count($tally_in->rowIds)) {
    foreach ($tally_in->rowIds as $key=>$id) {
        $component1= ComponentPeer::retrieveByPK($id);?>
        <tr class="sf_admin_row_<?php echo $key%2?>">
            <input type="hidden" name="rowIds[]" id ="rowIds"  class = "ExistComponents" value="<? echo $component1->getId()?>"/>
            <td><?echo $component1->getProductcode()?></td>
            <td><?echo $component1->getDescription()?></td>
            <td><?echo $component1->getBrand()?></td>
            <td><?echo $component1->getComponentunit()?></td>
            <td><input type="hidden" name="qty2s[]" id ="qty2s" size="7"  value="<? echo $tally_in->qty2s[$key]?>">
            <input type="text" name="qty3s[]" id ="qty3s" size="7" disabled value="<? echo $tally_in->qty2s[$key]?>">
            </td>
            <td><input type="text" name="qtys[]" id ="qtys" size="10" value ="<?echo $tally_in->qtys[$key]?>"></td>
            
        </tr>
<?} } elseif (isset($compsList)) {
    foreach ($compsList as $key=>$comps) {
        $comp= ComponentPeer::retrieveByPK($comps->getComponentId());
        $c = new Criteria();
        $c->add(ComponentsPeer::COMPONENTGROUP_ID, $tally_in->getComponentgroupId());
        $c->add(ComponentsPeer::COMPONENT_ID, $comp->getId());
        $TIcomps = ComponentsPeer::doSelectOne($c);
        ?>
        <tr class="sf_admin_row_<?php echo $key%2?>">
            <input type="hidden" name="rowIds[]" id ="rowIds"  class = "ExistComponents" value="<? echo $comp->getId()?>"/>
            <td><?echo $comp->getProductcode()?></td>
            <td><?echo $comp->getDescription()?></td>
            <td><?echo $comp->getBrand()?></td>
            <td><?echo $comp->getComponentunit()?></td>

            <td><input type="hidden" name="qty2s[]" id ="qty2s" size="7"  value="<? echo $comps->getQty1() - $comps->getQty4()?>">
            <input type="text" name="qty3s[]" id ="qty3s" size="7" disabled value="<? echo $comps->getQty1() - $comps->getQty4()?>">
            </td>
            <td><input type="text" name="qtys[]" id ="qtys" size="10"  value ="<? echo $TIcomps? $TIcomps->getQty1(): ''?>"></td>
            
<?php }
}?>

</table>

</div>

<script type="text/javascript">
function BuildBomList(){
    var bom = $("tally_in_tallyno");
    var bomcomplist = $("BOMcomplist");
    bomcomplist.innerHTML = "";
    var bomid = bom.options[bom.selectedIndex].value;
    var link = '<?php echo url_for('tallyin/BuildListAjax') ?>';
    new Ajax.Updater('BOMcomplist', link + '?type=1&tallyno='+ bomid);
}
</script>